package com.service.impl;

import com.dao.CommentDao;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.pojo.Comment;
import com.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @author 李浩然
 * @version 1.0
 * @description: TODO
 * @date 2022/11/19 11:13
 */
@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentDao commentDao;

    @Override
    public boolean addComments(Comment comment) {
        int i = commentDao.addComment(comment);
         return  i<0? false:true;
    }

    @Override
    public List<Comment> findAll() {
        List<Comment> list = commentDao.findAll();
        return list;
    }

    @Override
    public List<Comment> findByPage(Integer currentPage, Integer pageSize) {
        Page<Object> objects = PageHelper.startPage(currentPage, pageSize);
        List<Comment> comments = commentDao.findPidNull();
        return comments;
    }
    @Override
    public List<Comment> findByPageByUsername(Integer currentPage, Integer pageSize,String username) {
        Page<Object> objects = PageHelper.startPage(currentPage, pageSize);
        List<Comment> comments = commentDao.findByPageByUsername(username);
        return comments;
    }
    @Override
    public List<Comment> findByPagePidNullByUsername(Integer currentPage, Integer pageSize,String username) {
        Page<Object> objects = PageHelper.startPage(currentPage, pageSize);
        List<Comment> comments = commentDao.findpidNullByUsername(username);
        return comments;
    }
    @Override
    public boolean deleteComment(Integer cId) {
        int i  = commentDao.deleteComment(cId);
        return  i<0? false:true;
    }

    @Override
    public List<Comment> findtargetByUsername(String username) {
        List<Comment> comments = commentDao.findpidNullByUsername(username);
        return comments;
    }

    @Override
    public List<Comment> findpidNullByUsername(String username) {
        List<Comment> comments = commentDao.findpidNullByUsername(username);
        return comments;
    }

    @Override
    public boolean addLikeNum(Integer cId) {
        int i = commentDao.addLikeNum(cId);
        return  i<0? false:true;
    }

    @Override
    public boolean redLikeNum(Integer cId) {
        int i = commentDao.redLikeNum(cId);
        return  i<0? false:true;
    }


}
